package com.nuoniu.sibanyun.controller.user;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.user.SysUserNoteType;
import com.nuoniu.sibanyun.service.user.ISysUserNoteTypeService;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 记事本内容 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2022-06-01
 */
@RestController
@RequestMapping("/user/noteType")
@Api(tags = "记事本内容类型管理")
public class SysUserNoteTypeController extends BaseController {

    @Autowired
    private ISysUserNoteTypeService typeService;

    @ApiOperation("获取所有")
    @GetMapping("getALl")
    public HttpResult getAll() {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("user_id", UserThreadLocal.get().getUserId());
        return HttpResult.ok(typeService.list(wrapper));
    }

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody SysUserNoteType type) {
        type.setUserId(UserThreadLocal.get().getUserId());
        typeService.saveOrUpdate(type);
        return HttpResult.ok();
    }


    @ApiOperation("删除")
    @DeleteMapping("delete")
    public HttpResult getAll(Long id) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("id", id);
        wrapper.eq("user_id", UserThreadLocal.get().getUserId());
        typeService.remove(wrapper);
        return HttpResult.ok();
    }
}
